package org.yxs.es.index;

import com.alibaba.fastjson.JSONObject;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

/**
 * @author: y-xs
 * @date: 2021/08/26 14:48
 * @description: @Document(indexName = "springboot", shards = 1, replicas = 1) 配置索引名称、分片数、副本数，项目启动时将会自动创建索引
 * @Id 指定id字段
 * @Field(type = FieldType.Keyword)  配置字段为关键字
 * @Field(type = FieldType.Text)   配置字段为普通文本字段
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Document(indexName = "springboot", shards = 1, replicas = 1)
public class SpringBootIndex {

    /**
     * 必须有id，这里的id是全局唯一的标识，等同于es中的"_id"
     */
    @Id
    private Long id;


    /**
     * type : 字段数据类型
     * analyzer : 分词器类型
     * index : 是否索引(默认:true)
     * Keyword : 短语,不进行分词
     */
    @Field(type = FieldType.Keyword)
    private String name;


    @Field(type = FieldType.Text)
    private String createTime;


    @Override
    public String toString() {
        return JSONObject.toJSONString(this);
    }


}
